package com.esm.sm800.sm800floating;

import com.esm.sm800.R;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class playVidioMp3 extends Activity {

    private VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 设置Activity为全屏
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_play_vidio_mp3);

        videoView = findViewById(R.id.videoView);

        // 获取传递过来的Intent对象的参数
        Intent intent = getIntent(); // 获取传递过来的Intent对象
        // 设置视频路径，可以是本地文件或网络URL
        String videoPath = intent.getStringExtra("mp3FilePath"); // 获取参数值
        Uri videoUri = Uri.parse(videoPath);
        videoView.setVideoURI(videoUri);

        // 创建MediaController对象，并将其与VideoView关联
        MediaController mediaController = new MediaController(this);
        videoView.setMediaController(mediaController);

        // 设置视频准备好后的回调函数
        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                // 视频准备好后开始播放
                videoView.start();
            }
        });
        // 设置视频播放完成的回调函数
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                finish();
            }
        });
    }
}